package cn.telling.telMarketCentre.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import cn.telling.product.vo.ShopProductVo;
import cn.telling.telMarketCentre.dao.ITelMarketSupplyDao;
import cn.telling.telMarketCentre.service.ITelMarketSupplyService;
/**
 * @Description: 通讯市场处理Service
 * @author liugeng
 * @version V1.0
 *
 */
@Service("telMarketSupplyService")
public class TelMarketSupplyServiceImpl implements ITelMarketSupplyService {
	@Autowired
	@Qualifier("telMarketSupplyDao")
	private ITelMarketSupplyDao telMarketSupplyDao;
	public ITelMarketSupplyDao getTelMarketSupplyDao() {
		return telMarketSupplyDao;
	}
	public void setTelMarketSupplyDao(ITelMarketSupplyDao telMarketSupplyDao) {
		this.telMarketSupplyDao = telMarketSupplyDao;
	}
	
	/**
	 * 加载通讯市场产品列表
	 */
	@Override
	public List<Map<String, String>> loadTelMarketProductList(String userId,String choose) {
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		
		List<Map<String, String>> telMarketList = telMarketSupplyDao.loadTelMarketProductList(choose);
		
		List<ShopProductVo> shopProductVoList = telMarketSupplyDao.getShopProductListNoPage(userId);
		
		List<String> shopProductVoProductIdList = new ArrayList<String>();
		if (shopProductVoList != null && shopProductVoList.size() > 0) {
			for(int i = 0; i < shopProductVoList.size(); i++) {
				shopProductVoProductIdList.add(String.valueOf(shopProductVoList.get(i).getProductId()));
			}
		}
		
		if(telMarketList != null && telMarketList.size() > 0){
			for(int i = 0; i < telMarketList.size(); i++){
				Map<String,String> tmp = telMarketList.get(i);
				if(!shopProductVoProductIdList.contains(tmp.get("productId"))){
					list.add(tmp);
				}
			}
		}
		return list;
	}
	
	/**
	 * 发布通讯市场类产品
	 */
	@Override
	public int insertTelMarketShopProduct(String productId, String supplyId,String shopId) {
		return telMarketSupplyDao.insertTelMarketShopProduct(productId, supplyId, shopId);
	}
	
	@Override
	public int insertTelMarketProduct(String shopProductId, String price, String stockNum, String gifts, String aftersale,String userId) {
		return telMarketSupplyDao.insertTelMarketProduct(shopProductId, price, stockNum, gifts, aftersale, userId);
	}
	
	/**获得通讯市场上月销量top N 的产品*/
	@Override
	public List<String> getTelMarketProductTop(int topValue) {
		return telMarketSupplyDao.getTelMarketProductTop(topValue);
	}
}
